using System;
using System.Collections.Generic;
using System.Text;
using ESBSimpleSamples.ServiceClient.Interfaces;
using ESBSimpleSamples.ServiceClient.ServiceRequests;
using esb = Microsoft.Practices.ESB;
using ESBSimpleSamples.ServiceClient.Itineraries;
using System.Xml;

namespace ESBSimpleSamples.ServiceClient.ServiceBrokers
{
    public class ESBServiceBroker : IServiceBroker<ItineraryRequest, XmlNode>
    {
        #region IServiceBroker Members

        public XmlNode SubmitRequestResponse(ItineraryRequest request)
        {
            XmlNode body = request.Body;
            using (esb.Process proxy = new esb.Process())
            {
                proxy.Url = "http://localhost/ESB.ItineraryServices.Response/ProcessItinerary.asmx";
                proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
                proxy.ItineraryValue = request.Header; 
                proxy.SubmitRequestResponse(ref body);
            }

            return body;
        }

        public void SubmitRequest(ItineraryRequest request)
        {
            //TODO - I've had no need for this so far
            throw new NotImplementedException();
        }

        #endregion
        
    }
}
